package com.woniuxy.food.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodskuclient.FoodSkuQueryClient;
import com.woniuxy.food.client.param.SearchFoodSkuByConditionParam;
import com.woniuxy.food.client.result.FoodSkuClientDto;
import com.woniuxy.food.infra.model.FoodSku;
import com.woniuxy.food.service.FoodSkuService;
import com.woniuxy.food.service.servicedto.FoodSkuServiceDto;
import com.woniuxy.food.service.serviceparam.SearchFoodSkuByConditionServiceParam;
import common.WoniuPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import java.util.List;

@RestController
public class FoodSkuQueryClientApiImpl implements FoodSkuQueryClient {
    @Autowired
    private FoodSkuService foodSkuService;
    @Override
    @Log("根据条件查询菜品sku")
    public Result<WoniuPage<FoodSkuClientDto>> searchFoodSkuByCondition(SearchFoodSkuByConditionParam param) {
        SearchFoodSkuByConditionServiceParam searchFoodSkuByConditionServiceParam = BeanUtil.toBean(param, SearchFoodSkuByConditionServiceParam.class);
        WoniuPage<FoodSkuServiceDto> woniuPage = foodSkuService.searchFoodSkuByCondition(searchFoodSkuByConditionServiceParam);
        WoniuPage<FoodSkuClientDto> page = BeanUtil.toBean(woniuPage, WoniuPage.class);
        return Result.success(page);
    }

    @Override
    @Log("根据快速查询码查询菜品sku")
    public Result<FoodSkuClientDto> searchFoodSkuByQQC(Integer[] ids) {
        FoodSkuServiceDto foodSkuServiceDto = foodSkuService.searchFoodSkuByQQC(ids);
        FoodSkuClientDto foodSkuClientDto = BeanUtil.toBean(foodSkuServiceDto, FoodSkuClientDto.class);
        return Result.success(foodSkuClientDto);
    }

    @Override
    @Log("根据菜品skuID查询菜品sku")
    public Result<FoodSkuClientDto> searchFoodSkuById(Integer skuId) {
        FoodSkuServiceDto foodSkuServiceDto = foodSkuService.searchFoodSkuById(skuId);
        FoodSkuClientDto foodSkuClientDto = BeanUtil.toBean(foodSkuServiceDto, FoodSkuClientDto.class);
        return Result.success(foodSkuClientDto);
    }

    @Override
    @Log("根据菜品spuID查询菜品sku")
    public Result<List<FoodSkuClientDto>> searchFoodSkuBySpuId(Integer storeId, Integer spuId) {
        List<FoodSkuServiceDto> foodSkuServiceDtos = foodSkuService.searchFoodSkuBySpuId(storeId, spuId);
        List<FoodSkuClientDto> foodSkuClientDtos = BeanUtil.copyToList(foodSkuServiceDtos, FoodSkuClientDto.class);
        return Result.success(foodSkuClientDtos);
    }
}
